#include "history/indicator.h"

namespace sangame {
namespace history {

Indicator::Indicator()
{
}

#pragma region SG Message

bool Indicator::OnSetRect( base::Rect* message_ptr )
{
    m_tAxes.SetRect((RECT*)rect_param);

    return FALSE;
}

BOOL Indicator::OnMessage( int message_type, void* message_ptr )
{
    BOOL bHandled = FALSE;

    switch(message_type) {
    case MSG_INITCONTEXT:
        bHandled = OnSGInitContext((SGContext*)param_data);
        break;
    case MSG_GOODSCHANGE:
        bHandled = OnSGChangeGoods((SGGoodsChange*)param_data);
        break;
    case MSG_SYNCDATA:
        bHandled = OnSGSyncData((SGRange<uint64_t>*)param_data);
        break;
    case MSG_UPDATEAXES:
        bHandled = OnSGUpdateAxes();
        break;
    case MSG_DRAWBACK:
        bHandled = OnSGDrawBack((SGCanvas*)param_data);
        break;
    case MSG_DRAWFORE:
        bHandled = OnSGDrawFore((SGCanvas*)param_data);
        break;
    }

    return bHandled;
}

bool Indicator::OnSGInitContext( ContextMessage* message_ptr )
{
    int indicator_type = context_param->wparam;

    switch (indicator_type) {
    case SGIndicator::SG_INDICATOR_MAIN:
        m_pIndicatorBase = std::dynamic_pointer_cast<IndicatorBase, IndicatorMain>(
                               std::make_shared<IndicatorMain>(this));
        break;
    case SGIndicator::SG_INDICATOR_OVERLAY:
        m_pIndicatorBase = std::dynamic_pointer_cast<IndicatorBase, IndicatorOverlay>(
                               std::make_shared<IndicatorOverlay>(this));
        break;
    case SGIndicator::SG_INDICATOR_GOODS:
        m_pIndicatorBase = std::dynamic_pointer_cast<IndicatorBase, IndicatorGoods>(
                               std::make_shared<IndicatorGoods>(this));
        break;
    case SGIndicator::SG_INDICATOR_ARBITRAGE:
        m_pIndicatorBase = std::dynamic_pointer_cast<IndicatorBase, IndicatorArbitrage>(
                               std::make_shared<IndicatorArbitrage>(this));
        break;
    }

    return m_pIndicatorBase->OnSGInitContext(context_param);
}

BOOL Indicator::OnSGChangeGoods( SGGoodsChange* goods_change_param )
{
    return m_pIndicatorBase->OnSGGoodsChange(goods_change_param);
}

BOOL Indicator::OnSGSyncData( SGRange<uint64_t>* range_param )
{
    return m_pIndicatorBase->OnSGSyncData(range_param);
}

BOOL Indicator::OnSGDrawBack( SGCanvas* canvas_param )
{
    return m_pIndicatorBase->OnSGDrawBack(canvas_param);
}

BOOL Indicator::OnSGDrawFore( SGCanvas* canvas_param )
{
    return m_pIndicatorBase->OnSGDrawFore(canvas_param);
}

BOOL Indicator::OnSGUpdateAxes()
{
    m_tAxes.SetXValues(GetView()->GetLayout()->GetXValueList());

    return FALSE;
}

#pragma endregion SG Message

#pragma region SG Event

#pragma endregion SG Event

int Indicator::GetStatusID()
{
    return START_STATUS_ID;
}

#pragma region XMLString Status
BOOL Indicator::LoadXml( std::string& xml )
{
    return TRUE;
}

BOOL Indicator::SaveXml( std::string& xml )
{
    return TRUE;
}

void Indicator::OnStatusUpdate()
{
}

#pragma endregion XMLString Status

CHistoryView* Indicator::GetView()
{
    SGHandle handle_param;
    OnSGAccessMessage(CStdAccess<SGNull>::SGAccessMessage::SG_GETPARENT, 0, &handle_param);

    return (CHistoryView*)handle_param;
}

CAxes& Indicator::GetAxes()
{
    return m_tAxes;
}

}
}